package org.example.config;

import org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator;
import org.springframework.aop.config.AopConfigUtils;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

//@Configuration
public class TargetSourceCreateBean {

    @Autowired
    private BeanFactory beanFactory;

    @Bean(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME)
    public AnnotationAwareAspectJAutoProxyCreator annotationAwareAspectJAutoProxyCreator() {
        AnnotationAwareAspectJAutoProxyCreator creator = new AnnotationAwareAspectJAutoProxyCreator();
        // creator.setProxyTargetClass(true); 建议这里不要设置，还是取用注解的值来灵活控制最好了
        CustomTartSourceCreator myTargetSourceCreator = new CustomTartSourceCreator();
        myTargetSourceCreator.setBeanFactory(beanFactory);
        creator.setCustomTargetSourceCreators(myTargetSourceCreator);
        creator.setInterceptorNames("customInteceptor");
        return creator;
    }
}
